package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.ParamsValue;
import com.ruoyi.swla2.service.IParamsValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 基础参数Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/params/basicParams")
public class ParamsValueController extends BaseController {
    @Autowired
    private IParamsValueService paramsValueService;

    /**
     * 查询基础参数列表
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParamsValue paramsValue) {
        startPage();
        List<ParamsValue> list = paramsValueService.selectParamsValueList(paramsValue);
        return getDataTable(list);
    }

    /**
     * 导出基础参数列表
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:export')")
    @Log(title = "基础参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParamsValue paramsValue) {
        List<ParamsValue> list = paramsValueService.selectParamsValueList(paramsValue);
        ExcelUtil<ParamsValue> util = new ExcelUtil<ParamsValue>(ParamsValue.class);
        util.exportExcel(response, list, "基础参数数据");
    }

    /**
     * 获取基础参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID) {
        return success(paramsValueService.selectParamsValueByID(ID));
    }

    @PreAuthorize("@ss.hasPermi('params:basicParams:query')")
    @GetMapping(value = "/getCurrentBasicParams")
    public AjaxResult getCurrentBasicParams() {
        return success(paramsValueService.getCurrentBasicParams());
    }

    /**
     * 新增基础参数
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:add')")
    @Log(title = "基础参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParamsValue paramsValue) {
        paramsValue.setTenantId(this.getTenantId());
        return toAjax(paramsValueService.insertParamsValue(paramsValue));
    }

    /**
     * 修改基础参数
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:edit')")
    @Log(title = "基础参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParamsValue paramsValue) {
        return toAjax(paramsValueService.updateParamsValue(paramsValue));
    }

    /**
     * 删除基础参数
     */
    @PreAuthorize("@ss.hasPermi('params:basicParams:remove')")
    @Log(title = "基础参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs) {
        return toAjax(paramsValueService.deleteParamsValueByIDs(IDs));
    }
}
